<?php
namespace app\admin\controller;
use think\Db;
use think\facade\Request;
use app\admin\model\Week as weekModel;
class Week extends Common
{
    function index(){
        $weekModel = new weekModel();
        $list = $weekModel->weekAllList();

        $this->assign('list',$list);
        return $this->fetch('index');
    }

    function weekEdit(){
        if (request()->isAjax()) {
            $postData = input('post.');
            $weekid = input('post.weekid');
            $data['week_name'] = $postData['week_name'];
//            dump($data);exit;
            if($weekid > 0){
                $res = Db::name('week')->where("weekid",$weekid)->update($data);
                if($res !== false){
                    exitjson(1, '保存成功');
                }else{
                    exitjson(0, '保存失败');
                }
            }else{
                $res = Db::name('week')->insertGetId($data);
                if ($res) {
                    exitjson(1, '保存成功');
                } else {
                    exitjson(0, '保存失败');
                }
            }
        } else {
            if(input('weekid') > 0){
                $one = Db::name('week')->find(input('weekid'));
                $this->assign('one',$one);
            }
//            dump($one);exit;
            return $this->fetch('weekEdit');
        }
    }

    function weekDel(){
        $weekid = input('id');
        if($weekid>0){
            $data['is_del'] = 1;
            $res = Db::name('week')->where("weekid",$weekid)->update($data);
            if($res !== false){
                exitjson(1,'删除成功');
            }else{
                exitjson(0,'删除失败');
            }
        }
    }
}